from xgoedu import XGOEDU
dog = XGOEDU()


# 1. 显示文字
# dog.lcd_text(0, 0, '盛', color=(255, 0, 0), fontsize=200)

# 2. 显示方位
# dog.lcd_text(150, 0, '北', color=(255, 0, 0), fontsize=20)
# dog.lcd_text(150, 210, '南', color=(255, 0, 0), fontsize=20)
# dog.lcd_text(0, 100, '西', color=(255, 0, 0), fontsize=20)
# dog.lcd_text(300, 100, '东', color=(255, 0, 0), fontsize=20)


# 3. 长内容超出
# content = "吾十有五而志于学，三十而立，四十而不惑，五十而知天命，六十而耳顺，七十而从心所欲，不逾矩。"
# dog.lcd_text(0, 0, content, color=(255, 0, 0), fontsize=20)

# 4. 练习，实现根据内容长度，自动换行显示

def display_texts(content, color, start_x=2, start_y=2,
                  font_size=20, screen_width=320, screen_height=240):
    # dog = XGOEDU()
    char_width = font_size + 1
    chars_per_line = screen_width // char_width
    chars = list(content)
    total_lines = len(chars) // chars_per_line + 1
    current_char = 0
    for line in range(total_lines):
        current_x = start_x
        current_y = start_y + line * char_width
        for _ in range(chars_per_line):
            if current_char >= len(chars):
                break
            char = chars[current_char]
            dog.lcd_text(current_x, current_y, char, color, font_size)
            current_x += char_width
            current_char += 1

        if current_char >= len(chars):
            break


# content = '''吾十有五而志于学，三十而立，四十而不惑，五十而知天命，六十而耳顺，七十而从心所欲，不逾矩。'''
# display_texts(content,(255,0,0))

dog.lcd_line(50,50,150,150,(255,0,0),4)
dog.lcd_line(50,90,150,190,(0,255,0),10)